﻿using System;
using System.Collections.Generic;
using System.ComponentModel;

namespace HostEdit
{
    public class Host : INotifyPropertyChanged
    {

        public Host()
        {
            Address = new IndexedObservableCollection<Adress, string>(c => c.Value);
        }


        private string _Name;
        public String Name
        {
            get
            {
                return _Name;
            }
            set
            {
                if (_Name == value) return;
                _Name = value;
                if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("Name"));
            }
        }

        public IndexedObservableCollection<Adress, String> Address { get; set; }

        public event PropertyChangedEventHandler PropertyChanged;


        internal List<Entry> Save()
        {
            List<Entry> l = new List<Entry>();
            foreach (Adress  i in this.Address)
                l.Add(new Entry() { Host = Name, Active = i.Active, Ip = i.Value });
            return l;
        }

        internal Host Copy()
        {
            Host h = new Host() { Name = Name };
            foreach (var m in this.Address)
            {
                Adress a = new Adress() { Active = m.Active, Host = h, Value = m.Value };
                h.Address.Add(a);
            }

            return h;
        }
    }
}
